<%@ page contentType="text/html; charset=UTF-8" %>
<%@page import="cn.bopomo.dealer.base.common.CommonConstant"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<html:html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
		<title>操作员管理</title>
		<script language="javascript" src="/js/json2.js"></script>
		<script language="javascript" src="/js/litpen_ajax.js"></script>
		<script language="javascript" src="/js/json2.js"></script>
		<script language="javascript" src="/js/litpen_ajax.js"></script>
		<style type="text/css">
		.spanDiv{
			margin:10px;
		}
		.test{
			/*display:none;*/
			width:360px;
			margin: auto;
			position:absolute;
			background-color: #f2f6fb;
			border:1px solid #56626d;
			
		}
		
		.test table{
			font-size:12px;
		}
		.test table tr{
		border-bottom:1px solid #56626d;
		}
		.selectStyle{
			width:100px;
		}
		.even1{
			background-color:#eeeeee;
		}
		.even2{
			background-color:#DDDDDD;
		}
		.td-font{
			color:#03c;font-weight:bold;
		}
		</style>
		<script language="javascript" type="text/javascript">
			function showDiv(id,cbFunction){
				var moveDiv = document.getElementById("moveDiv");
				
				moveDiv.style.left = document.body.clientWidth / 2 - 360/2;
				
				moveDiv.style.top = document.body.clientHeight / 2 - 400/2;
				var selects = document.getElementsByTagName("select");
				for (var i = 0; i<selects.length;i++){
					selects[i].style.display = "none";
				}
				var form_selects = moveDiv.getElementsByTagName("select");
				for (var j = 0; j<form_selects.length;j++){
					form_selects[j].style.display = "block";
				} 
				if (arguments.length>1){
					cbFunction = arguments[1];
					id = arguments[0];
				}else{
					id = null;
					cbFunction = arguments[0];
				}
				var action = "";
				if (id == 'undefined' || id == null){
					action = "/admin/loadOPGroupAjax.do"; //add
				}else{
					action = "/admin/loadOPGroupAjax.do?oid=" + id; //modify
				}
				var sendAjax = new Ajax(action,null,true,cbFunction,"get");
				sendAjax.send();
				
				moveDiv.style.display = "block";
			}
			
			function addOPCallBack(){
				var result = arguments[0];
				var myData = JSON.parse(result,null);
				var form = document.forms['OperatorForm'];
				var toList = form.to;
				var fromList = form.from;
				toList.innerHTML = "";
				fromList.innerHTML = "";
				for (var i = 0; i<myData.toArray.length;i++){
					var txt = myData.toArray[i].groupName;
					var val = myData.toArray[i].gid;
					toList.options[i] = new Option(txt,val);
				}
				for (var j = 0; j<myData.fromArray.length;j++){
					var txt = myData.fromArray[j].groupName;
					var val = myData.fromArray[j].gid;
					fromList.options[j] = new Option(txt,val);
				}
				
			}
			
			
			function editOPCallBack(){
				var result = arguments[0];
				var myData = JSON.parse(result,null);
				var form = document.forms['OperatorForm'];
				var toList = form.to;
				var fromList = form.from;
				toList.innerHTML = "";
				fromList.innerHTML = "";
				for (var i = 0; i<myData.toArray.length;i++){
					var txt = myData.toArray[i].groupName;
					var val = myData.toArray[i].gid;
					toList.options[i] = new Option(txt,val);
				}
				for (var j = 0; j<myData.fromArray.length;j++){
					var txt = myData.fromArray[j].groupName;
					var val = myData.fromArray[j].gid;
					fromList.options[j] = new Option(txt,val);
				}
				form.loginName.value = myData.loginName;
				form.hasChild.checked = myData.hasChild;
			}
			
			function closeDiv(){
				var selects = document.getElementsByTagName("select");
				for (var i = 0; i<selects.length;i++){
					selects[i].style.display = "";
				}
				var moveDiv = document.getElementById("moveDiv");
				moveDiv.style.display = "none";
			}
		/* wen qing here*/	
			






			
			/* -----发送AJAX请求_获取操作员列表-----*/
			var oid = <%=request.getParameter("oid")%>
			
			
			function gotoPage(url){
				//alert(url);
				loadOperatorList(url);
			}
			
			
			
			/* -----发送AJAX请求_获取操作员列表-----*/
			function loadOperatorList1(){
				var loadOperatorList_ajax = new Ajax("/admin/loadOperatorListAjax.do?oid="+oid,null,true,loadOperatorListCallback,"get");
				loadOperatorList_ajax.send();
			}
			
			function loadOperatorList(url){
				var loadOperatorList_ajax = new Ajax(
											url,
											null,
											true,
											loadOperatorListCallback,
											"get");
				loadOperatorList_ajax.send();
			}
			
			/* -----接收AJAX返回信息_获取操作员列表-----*/
			function loadOperatorListCallback(){
				var result = arguments[0];
				//alert(result);
				var myData = JSON.parse(result,null);
				document.getElementById("pageStr").innerHTML=myData.pageStr;
				
				var oTBody = document.getElementById("tbody");
				for( i = 0 ; i <= oTBody.rows.length+1 ; i++)
				  oTBody.deleteRow();
				  
				var oRow;
				var oCellId;
				for (var i = 0; i < myData.operators.length; i++){
					oRow = document.createElement("TR");
					if (i % 2 == 0){
						oRow.className= "even1";
					}else{
						oRow.className= "even2";
					}
					
					oTBody.appendChild(oRow);
					oCellId = document.createElement("TD");
					oCellId.innerText = myData.operators[i].id;
					oRow.appendChild(oCellId);
					
					oCellName = document.createElement("TD");
					oCellName.innerText = myData.operators[i].loginName;
					oRow.appendChild(oCellName);
					
					oCellTmp = document.createElement("TD");
					oCellTmp.innerText = myData.operators[i].addDate;
					oRow.appendChild(oCellTmp);
					
					oCellOp = document.createElement("TD");
					oCellOp.innerHTML = '<input type="button" value="编辑" onclick="javascript:pre_editGroup(' + myData.operators[i].id + ');"/>&nbsp;&nbsp;&nbsp;<input type="button" value="删除" onclick="javascript:deleteGroup(' + myData.operators[i].id + ');"/>';
					oRow.appendChild(oCellOp);
				}
			

			}	
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
		</script>
	</head>
	<body><button onClick="gotoPage('/admin/loadOperatorListAjax.do');" id="btnTest">btnTest</button>
	<div>
		<TABLE width="95%" align="center" cellpadding="2" cellspacing="1" bgcolor="#FFFFFF" style="border:1px solid #56626d;font-size:12px">

		  <TR bgcolor="#FFFFFF">
		    <TD colspan="3" align="left" style="font-size:14px"><B>&nbsp;&nbsp;操作员列表</B></TD>
		  </TR>
		  <TR bgcolor="#FFFFFF">
		    <TH width="5%" style="background:#46525d;text-align: center;">
		    	<span style="background:#46525d;color:#FFFFFF;text-align: center;">
		    		编号
				</span>
			</TH>
		    <TH width="15%" style="background:#46525d;text-align: center;">
		    	<span style="background:#46525d;color:#FFFFFF;text-align: center;">
		    		名称
				</span>
		    <TH width="10%" style="background:#46525d;text-align: center;">
		    	<span style="color:#FFFFFF">
		    		建立日期
		    	</span>
		    </TH>
		    <TH width="10%" style="background:#46525d;text-align: center;">
		    	<span style="color:#FFFFFF">
		    		操作
		    	</span>
		    </TH>
		  </TR>

			<%	String pageList=CommonConstant.KEY_OPERATOR_LIST_PAGE; 	%>
			<logic:notPresent name="<%=pageList%>">
			  	<TR bgcolor="#EEEEEE">
			    	<TD nowrap align="center" colspan="20" >没有找到相关的信息</TD>
				</TR>
			</logic:notPresent>
			<logic:present name="<%=pageList%>">
				<logic:iterate id="dl" indexId="ind" name="<%=pageList%>" property="list">
					<% if(ind.intValue()%2==0){%> 
						<TR bgcolor="#EEEEEE">
					<% } else { %>
       					<TR bgcolor="#DDDDDD">
					<% } %>
						    <TD nowrap align="center">
								<bean:write name="dl" property="id" />
							</TD>
						    <TD nowrap align="center">
						    	<span style="color:#03c;font-weight:bold;">
									<bean:write name="dl" property="loginName" />
								</span>
							</TD>
						    <TD nowrap align="center">
								<bean:write name="dl" property="addDate" format="yyyy-MM-dd"/>
						    </TD>
						    <TD nowrap align="center">
					    		<button onClick="showDiv(1,editOPCallBack);">
									编辑
								</button>
						    </TD>
				  </TR>
				</logic:iterate>	
				
						
						
			</logic:present>
		</TABLE>
		<div id="datalist">
			加载中.....
		</div>
		<div>

		<div id="pageStr"></div>
		</div>
		<div class="test" id="moveDiv">
			<form name="OperatorForm">
				<table width="360" height="400">

				<tr style="border:1px solid #56626d;">
				<td align="right"><label for="loginName">用户名：</label></td><td><input type="text" name="loginName"></td>
				</tr>
				<tr>
					<td align="right"><label for="password">密&nbsp;&nbsp;码：</label></td>
					<td><input type="password" name="password"></td>
				</tr>
				<tr>
					<td align="right"><label for="confrmPwd">确认密码：</label></td><td><input type="password" name="confrmPwd"></td>
				</tr>
				<tr>
					<td align="right"><label for="hasChild">是否允许增加子操作员：</label></td><td><input type="checkbox" name="hasChild"></td>
				</tr>
				<tr>
					<td align="right">权限组选择：</td><td></td>
				</tr>
				<tr>
					<td align="center" colspan="2">
						<table>
							<tr>
								<td>
								<select size="10"  multiple name="from" class="selectStyle" id="from"  >
								</select>
								</td>
								<td>
									<button onClick="copyAll('from','to');">->></button><br/>
									<button onClick="copyToList('from','to');">--></button><br/>
									<button onClick="copyToList('to','from');"><--</button><br/>
									<button onClick="copyAll('to','from');"><<-</button>
								</td>
								<td>
									<select size="10"  multiple name="to" class="selectStyle">
									</select>
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td align="center" colspan="2"><button onClick="submitAdd(this);" name="btnAction">添加</button>&nbsp;&nbsp;&nbsp;<button onClick="clearGroupForm();" name="btnCancel">取消</button></td>
				</tr>
				</table>
			</form>
		<button onClick="closeDiv();">关闭</button>asdfasdfsadfasf
		
		</div>
			<script language="javascript" type="text/javascript">
		  		loadOperatorList("/admin/loadOperatorListAjax.do");
		  	</script>
	</body>
</html:html>
